<?php
namespace app\api\controller;
use \app\api\model\UserModel;
use \app\api\Common\Common;

class User extends Common
{
    public function index(){
        $option = input("option");

        if(!method_exists($this,$option)){
            die('{"code":0,"info":"接口不存在"}');
        }
        //实例化用户模型
        $model = new UserModel();
        //根据传入的参数调用不同的方法
        $this->$option($model);
    }
    public function register($model){//用户注册模块
        $username = input("username");
        $userpwd = input("password");
        $phone = input("phone");
        $arr = $model->getUserByName($username);
        if(!empty($arr)|| empty($username) || empty($userpwd)||empty($phone)){
            $this->Json(0,"","接口参数错误或用户名已存在");
        }else{
            $userpwd = md5(md5($userpwd).'520');
            $regTime = date('Y-m-d h:i:s', time());
            $model->register($username, $userpwd, $phone, $regTime);
        } 
    }
}